package com.eternal.control.view;

import android.graphics.Paint;

import androidx.annotation.NonNull;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;

import com.eternal.framework.utils.ConvertUtils;

/**
 * Created by Administrator
 * On 2020/5/4
 * Description:
 * @author Administrator
 */
public class UpSpan extends MetricAffectingSpan {
    private float size;

    public UpSpan(float size) {
        this.size = ConvertUtils.sp2px(size);
    }

    @Override
    public void updateMeasureState(@NonNull TextPaint textPaint) {
        Paint.FontMetrics old=textPaint.getFontMetrics();
        textPaint.setTextSize(size);
        Paint.FontMetrics newMetrics=textPaint.getFontMetrics();
        textPaint.baselineShift+=((old.top-old.bottom)-(newMetrics.top-newMetrics.bottom))/2;
    }

    @Override
    public void updateDrawState(TextPaint tp) {
        Paint.FontMetrics old=tp.getFontMetrics();
        tp.setTextSize(size);
        Paint.FontMetrics newMetrics=tp.getFontMetrics();
        tp.baselineShift+=((old.top-old.bottom)-(newMetrics.top-newMetrics.bottom))/2;
    }
}
